// pages/questionlist/questionlist.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    loading:true,
    questionid:'a',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          height: res.windowHeight
        })
      }
    })
    that.getData();
   
    
  },
  onShow: function () {
    this.getData();
  },
  getData:function(){
    var that = this;
    //普通用户个人接口
    app.getLoginSession(function (session) {
      wx.request({
        url: app.api,
        data: {
          app: 'member',
          act: 'myDetail',
          t_session: session
        },
        success: function (res) {
          var data = res.data;
          if (data.done && data.retval) {
            that.setData({
              count: data.retval.count,
              member: app.turn(data.retval.member),
            })
            console.log(that.data.member);
            if (that.data.member[0].is_doctor == 1) {
              that.setData({
                doctor: "a",
                doctor_id: data.retval.doctor_id
              })
              wx.request({
                url: app.api,
                data: {
                  app: 'doctor',
                  act: "myDoctor",
                  t_session: session
                }, success: function (res) {
                  var data = res.data;
                  if (data.done && data.retval) {
                    if (app.turn(data.retval.consultArr).length > 0) {
                      console.log("aaa");
                      that.setData({
                        loading: false,
                        consultArr: app.turn(data.retval.consultArr)
                      })
                    } else {
                      that.setData({
                        loading: false,
                        loadTips: '暂无数据'
                      })
                    }
                  }
                },
                fail: function () {
                  that.setData({
                    loading: true,
                    errorTips: 'app:myDoctor连接失败'
                  })
                }
              })
            } else {
              that.setData({
                doctor: "b"
              })
              app.getLoginSession(function (session) {
                wx.request({
                  url: app.api,
                  data: {
                    app: 'member',
                    act: 'myInformation',
                    t_session: session
                  },
                  success: function (res) {
                    var data = res.data;
                    if (data.done && data.retval) {
                      if(data.retval.length==0){
                        that.setData({
                          loading: false,
                          loadTips: '暂无数据！'
                        })
                      }else{
                        that.setData({
                          list: app.turn(data.retval),
                          loading: false
                        })
                      }
                    } else {
                      that.setData({
                        loading: false,
                        loadTips: '暂无数据！'
                      })
                    }
                  },
                  fail: function () {
                    that.setData({
                      loading: true,
                      errorTips: 'app:member连接失败'
                    })
                  }
                })
              })
            }
          }
        },
        fail: function (res) {
          that.setData({
            loading: true,
            errorTips: "app:menber连接失败"
          })
        }
      })
    })
  },
  // 展示问题
  show_question: function (e) {
    var that = this;
    var id = e.currentTarget.dataset.id;
    if (that.data.questionid != id) {
      that.setData({
        questionid: id
      })
    } else {
      that.setData({
        questionid: 'a'
      })
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },
  showimg:function(event){

  },
  showimg:function(event){
    console.log(event); 
    var img = event.currentTarget.dataset.img[event.target.dataset.id];
    var url = event.currentTarget.dataset.img
    console.log(img+"aaa"+url);
    wx.previewImage({
      current: img, // 当前显示图片的http链接
      urls: url// 需要预览的图片http链接列表
    })
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})